# -*- coding: utf-8 -*-
# @Author : zhaochen
# @Date   : 2019/7/29
# @File   : EG05_Past6MonsDepositAvgBal_GZ.py
# @E-mail : zhaochen@bbdservice.com

'''eof
name:过去6个月存款余额
code:EG05_Past6MonsDepositAvgBal_GZ
tableName:
columnName:
groups:企业通用模块
dependencies:TX_GZ_DSJ,EG_DSJ,CQB_DSJ
type:常用指标
datasourceType:在线指标
description:
eof'''


import sys
import pandas as pd
import json
from datetime import datetime


def FormatData(tableName):
    try:
        ic = CQB_DSJ.get("data").get(tableName)
        return ic if isinstance(ic, list) else [{}]
    except:
        return [{}]


def is_num(num):
    try:
        float(num)
        return True
    except:
        return False


def getEG05():
    null_type_list = ['', ' ', None, 'null', 'Null', 'NULL', '/', '-', '--']
    try:
        depositInfo = FormatData("depositInfo")
        if depositInfo == [{}]:
            return u'缺失值'
        else:
            if len(depositInfo) >= 1:
                for i in depositInfo:
                    deposit = i.get("HIS_6_AVG_DEPOSIT")
                    if deposit not in null_type_list and is_num(deposit):
                        return '%.4f' % float(deposit)
                    else:
                        return u'缺失值'
                return u'缺失值'
            else:
                return 0
    except:
        return u'缺失值'


result = getEG05()

